import {
    createStore,
    applyMiddleware
} from "redux"
import thunk from "redux-thunk"
let initValue = {
    user_list: [],
    select_user: {},
    product_list: []
}

let reducer = (state = initValue, action) => {

    switch (action.type) {
        case "SET_USER_LIST":
            state.user_list = action.data;
            break;
        case "ADD_USER":
            action.data.id = new Date().getTime();
            action.data.key = new Date().getTime();
            action.updateTime = new Date().getTime();
            state.user_list.unshift(action.data);
            break;
        case "EDIT_USER":
            let index = state.user_list.findIndex(item => item.id === action.data.id);
            state.user_list[index] = action.data;
            break;

        case "SELECT_USER":
            state.select_user = action.data;
            break;

        case "DELETE_USER":
            break;


        default:



    }

    return JSON.parse(JSON.stringify(state))
}
export default createStore(reducer, applyMiddleware(thunk))